package com.lch.algorithm;

/**
 * 判断回文整数，如果为负数返回false
 *
 * 121 true  10 false  -121 false
 *
 * 思路转为字符串，采用双指针
 *
 * @author 刘晨辉
 * @date 2021/8/16 10:01 下午
 */
public class Palindrome {

    public static void main(String[] args) {
        int in = 12221;
        String inStr = String.valueOf(in);
        char[] chars = inStr.toCharArray();
        boolean flag = true;
        for (int i = 0, j = chars.length - 1; i < j; i++, j--) {
            if (chars[i] != chars[j]) {
                System.out.println(false);
                flag = false;
            }
        }
        if (flag) {
            System.out.println(true);
        }
    }
}
